import { store } from "@/store";
import { defineStore } from "pinia";
import { fetchGetCollegeList,fetchGetMajorList,fetchGetGradeList,fetchGetSocietyTypeList} from "@/api/public/index";

const usePublicStore = defineStore({
  id: "vitality-public",
  state: () => {
    return {
      collegeList: [], // 学院数据
      majorList: [], // 专业数据
      gradeList: [], // 年级数据
      societyTypeList: [], //社团类型数据
    };
  },

  getters: {},

  actions: {
    /**
     * 获取学院列表
     */
    async getCollegeList() {
      const res = await fetchGetCollegeList();
      this.collegeList = res.data.data;
      return res;
    },
    /**
     * 获取学院列表
     */
    async getMajorList() {
      const res = await fetchGetMajorList();
      this.majorList = res.data.data;
      return res;
    },
    /**
     * 获取年级列表
     */
    async getGradeList() {
      const res = await fetchGetGradeList();
      this.gradeList = res.data.data;
      return res;
    },
    /**
     * 获取社团列表
     */
    async getSocietyList() {
      const res = await fetchGetSocietyTypeList();
      this.societyTypeList = res.data;
      return res;
    },
  },
});

export default usePublicStore;
export function usePublicStoreHook() {
  return usePublicStore(store);
}
